package com.monkeyboy.mongo_demo;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author Gavin
 * @date 2021.01.11 11:37
 */
public class DateUtil {
    /**
     * Date to String
     */
    public static String dateToString(String pattern, Date date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        return simpleDateFormat.format(date);
    }

    /**
     * String to Date
     */
    public static Date stringToDate(String pattern, String date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        Date d = null;
        try {
            d = simpleDateFormat.parse(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return d;
    }
}
